import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

let user = uni.getStorageSync('user') || {}
const store = new Vuex.Store({
	state: {
		user: user,
		collapse: false,
		device: 'desktop',
		withoutAnimation: false
	},
	mutations: {
		login(state, user) {
			state.user = user
			uni.setStorageSync('user', user)
		},
		logout(state) {
			state.user = {}
			uni.removeStorageSync('user')
		},
		toggleSidebar(state) {
			state.collapse = !state.collapse;
			state.withoutAnimation = false;
		},
		closeSidebar(state, withoutAnimation) {
			state.collapse = true;
			state.withoutAnimation = withoutAnimation
		},
		toggleDevice(state, device) {
			state.device = device
		},
	}
})

export default store
